<template>
  <view class="u-p-30 u-p-t-24">
    <view class="u-flex u-row-between">
      <view class="u-font-32 font-b" style="color: #101010">发布评论</view>
      <view class="font-28 font-b publish-btn" @click="publish">发布</view>
    </view>
    <view class="u-m-t-30">
      <u-field
          v-model="content"
          placeholder="请输入"
          type="textarea"
          :label-width="0"
          :field-style="fieldStyle"
      />
    </view>
    <u-toast ref="toast" />
  </view>
</template>

<script>
import {request} from "../../util/api";

export default {
  name: "add",
  data() {
    return {
      content: '',
      fieldStyle: {
        border: '1px solid rgba(187, 187, 187, .29)',
        borderRadius: '3px',
        padding: '4px',
        minHeight: '100px'
      },
      id: '',
      type: ''
    }
  },

  onLoad(option) {
    this.id = option.id
    this.type = option.type
  },

  methods: {
    publish() {
      if (!this.content) {
        this.$refs.toast.show({title: '请输入评论！', type: 'warning'})
        return
      }
      if (this.type === 'class') {
        request({
          url: '/system/CompassVideoEva',
          method: 'post',
          data: {
            videoId: this.id,
            evaDesc: this.content
          }
        }).then(res => {
          uni.showModal({
            title: '提示',
            content: '发表评论成功',
            showCancel: false,
            success: function (res) {
              uni.navigateBack()
            }
          })
        })
      } else {
        request({
          url: '/system/CompassGoodsEva',
          method: 'post',
          data: {
            goodsId: this.id,
            evaDesc: this.content
          }
        }).then(res => {
          uni.showModal({
            title: '提示',
            content: '发表评论成功',
            showCancel: false,
            success: function (res) {
              uni.navigateBack()
            }
          })
        })
      }
    }
  }
}
</script>

<style scoped lang="scss">
  /deep/.u-field {
    padding: 0!important;
  }
  .publish-btn {
    background: $btn_active_bg_color;
    padding: 10upx 40upx;
    border-radius: 8upx;
    color: #fff;
  }
</style>
